/*   1:    */ package org.intellij.lang.regexp.intention;
/*   2:    */ 
/*   3:    */

import com.intellij.ide.util.PropertiesComponent;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonShortcuts;
import com.intellij.openapi.actionSystem.CustomShortcutSet;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.event.DocumentAdapter;
import com.intellij.openapi.editor.event.DocumentEvent;
import com.intellij.openapi.fileTypes.PlainTextFileType;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.popup.Balloon;
import com.intellij.openapi.ui.popup.JBPopupAdapter;
import com.intellij.openapi.ui.popup.LightweightWindowEvent;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.Ref;
import com.intellij.openapi.wm.IdeFocusManager;
import com.intellij.psi.PsiDocumentManager;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.impl.source.resolve.FileContextUtil;
import com.intellij.ui.BalloonImpl;
import com.intellij.ui.EditorTextField;
import com.intellij.ui.Gray;
import com.intellij.ui.JBColor;
import com.intellij.util.Alarm;
import com.intellij.util.Alarm.ThreadToUse;
import com.intellij.util.ui.UIUtil;
import org.intellij.lang.regexp.RegExpLanguage;
import org.intellij.lang.regexp.RegExpModifierProvider;

import javax.swing.*;
import javax.swing.border.CompoundBorder;
import javax.swing.border.EmptyBorder;
import javax.swing.border.LineBorder;
import java.awt.*;
import java.util.regex.Pattern;

/*   4:    */
/*   5:    */
/*   6:    */
/*   7:    */
/*   8:    */
/*   9:    */
/*  10:    */
/*  11:    */
/*  12:    */
/*  13:    */
/*  14:    */
/*  15:    */
/*  16:    */
/*  17:    */
/*  18:    */
/*  19:    */
/*  20:    */
/*  21:    */
/*  22:    */
/*  23:    */
/*  24:    */
/*  25:    */
/*  26:    */
/*  27:    */
/*  28:    */
/*  29:    */
/*  30:    */
/*  31:    */
/*  32:    */
/*  33:    */
/*  34:    */
/*  35:    */
/*  36:    */
/*  37:    */
/*  38:    */
/*  39:    */
/*  40:    */
/*  41:    */
/*  42:    */
/*  43:    */
/*  44:    */ 
/*  45:    */ public class CheckRegExpForm
/*  46:    */ {
/*  47:    */   private static final String a = "last.edited.regexp";
/*  48:    */   private Pair<PsiFile, Ref<Balloon>> b;
/*  49:    */   private EditorTextField c;
/*  50:    */   private EditorTextField d;
/*  51:    */   private JPanel e;
/*  52:    */   private Ref<Balloon> f;
/*  53:    */   private Project g;
/*  54:    */   
/*  55:    */   public CheckRegExpForm(Pair<PsiFile, Ref<Balloon>> paramPair)
/*  56:    */   {
/*  57: 70 */     this.b = paramPair;
/*  58: 71 */     c();
/*  59:    */   }
/*  60:    */   
/*  61:    */   private void a()
/*  62:    */   {
/*  63: 74 */     PsiFile localPsiFile = (PsiFile)this.b.first;
/*  64: 75 */     this.g = localPsiFile.getProject();
/*  65: 76 */     this.f = ((Ref)this.b.second);
/*  66: 77 */     Document localDocument = PsiDocumentManager.getInstance(this.g).getDocument(localPsiFile);
/*  67:    */     
/*  68: 79 */     this.d = new EditorTextField(localDocument, this.g, RegExpLanguage.INSTANCE.getAssociatedFileType());
/*  69: 80 */     String str = PropertiesComponent.getInstance(this.g).getValue("last.edited.regexp", "Sample Text");
/*  70: 81 */     this.c = new EditorTextField(str, this.g, PlainTextFileType.INSTANCE);
/*  71: 82 */     this.c.setBorder(new CompoundBorder(new EmptyBorder(2, 2, 2, 4), new LineBorder(UIUtil.isUnderDarcula() ? Gray._100 : UIUtil.getBorderColor())));
/*  72:    */     
/*  73: 84 */     this.c.setOneLineMode(false);
/*  74: 85 */     this.c.addDocumentListener(new DocumentAdapter()
/*  75:    */     {
/*  76:    */       public void documentChanged(DocumentEvent paramAnonymousDocumentEvent)
/*  77:    */       {
/*  78: 89 */         SwingUtilities.invokeLater(new Runnable()
/*  79:    */         {
/*  80:    */           public void run()
/*  81:    */           {
/*  82: 91 */             CheckRegExpForm.this.e.revalidate();
/*  83: 92 */             Balloon localBalloon = (Balloon)CheckRegExpForm.this.f.get();
/*  84: 93 */             if (localBalloon != null) {
/*  85: 94 */               localBalloon.revalidate();
/*  86:    */             }
/*  87:    */           }
/*  88:    */         });
/*  89:    */       }
/*  90:100 */     });
/*  91:101 */     this.e = new JPanel(new BorderLayout())
/*  92:    */     {
/*  93:    */       public void addNotify()
/*  94:    */       {
/*  95:104 */         super.addNotify();
/*  96:105 */         IdeFocusManager.getGlobalInstance().requestFocus(CheckRegExpForm.this.c, true);
/*  97:    */         
/*  98:107 */         new AnAction()
/*  99:    */         {
/* 100:    */           public void actionPerformed(AnActionEvent paramAnonymous2AnActionEvent)
/* 101:    */           {
/* 102:110 */             IdeFocusManager.findInstance().requestFocus(CheckRegExpForm.this.d.getFocusTarget(), true);
/* 103:    */           }
/* 104:110 */         }.registerCustomShortcutSet(CustomShortcutSet.fromString(new String[] { "shift TAB" }), CheckRegExpForm.this.c, (Disposable)CheckRegExpForm.this.f.get());
/* 105:    */         
/* 106:    */ 
/* 107:113 */         AnAction local2 = new AnAction()
/* 108:    */         {
/* 109:    */           public void actionPerformed(AnActionEvent paramAnonymous2AnActionEvent)
/* 110:    */           {
/* 111:116 */             ((Balloon)CheckRegExpForm.this.f.get()).hide();
/* 112:    */           }
/* 113:118 */         };
/* 114:119 */         local2.registerCustomShortcutSet(CommonShortcuts.ESCAPE, CheckRegExpForm.this.d.getFocusTarget(), (Disposable)CheckRegExpForm.this.f.get());
/* 115:120 */         local2.registerCustomShortcutSet(CommonShortcuts.ESCAPE, CheckRegExpForm.this.c.getFocusTarget(), (Disposable)CheckRegExpForm.this.f.get());
/* 116:    */         
/* 117:    */ 
/* 118:123 */         ((Balloon)CheckRegExpForm.this.f.get()).addListener(new JBPopupAdapter()
/* 119:    */         {
/* 120:    */           public void onClosed(LightweightWindowEvent paramAnonymous2LightweightWindowEvent)
/* 121:    */           {
/* 122:126 */             PropertiesComponent.getInstance(CheckRegExpForm.this.g).setValue("last.edited.regexp", CheckRegExpForm.this.c.getText());
/* 123:    */           }
/* 124:129 */         });
/* 125:130 */         final Alarm localAlarm = new Alarm(Alarm.ThreadToUse.SWING_THREAD, (Disposable)CheckRegExpForm.this.f.get());
/* 126:131 */         DocumentAdapter local4 = new DocumentAdapter()
/* 127:    */         {
/* 128:    */           public void documentChanged(DocumentEvent paramAnonymous2DocumentEvent)
/* 129:    */           {
/* 130:134 */             localAlarm.cancelAllRequests();
/* 131:135 */             if (!localAlarm.isDisposed()) {
/* 132:136 */               localAlarm.addRequest(new Runnable()
/* 133:    */               {
/* 134:    */                 public void run()
/* 135:    */                 {
/* 136:139 */                   CheckRegExpForm.this.b();
/* 137:    */                 }
/* 138:139 */               }, 200);
/* 139:    */             }
/* 140:    */           }
/* 141:144 */         };
/* 142:145 */         CheckRegExpForm.this.d.addDocumentListener(local4);
/* 143:146 */         CheckRegExpForm.this.c.addDocumentListener(local4);
/* 144:    */         
/* 145:148 */         CheckRegExpForm.this.b();
/* 146:149 */         CheckRegExpForm.this.c.selectAll();
/* 147:    */       }
/* 148:    */     };
/* 149:    */   }
/* 150:    */   
/* 151:    */   public JPanel getRootPanel()
/* 152:    */   {
/* 153:156 */     return this.e;
/* 154:    */   }
/* 155:    */   
/* 156:    */   private void b()
/* 157:    */   {
/* 158:160 */     boolean bool = false;
/* 159:    */     try
/* 160:    */     {
/* 161:162 */       PsiFile localPsiFile1 = (PsiFile)this.b.first;
/* 162:    */       
/* 163:164 */       int i = -1;
/* 164:    */       try
/* 165:    */       {
/* 166:166 */         String str = localPsiFile1.getName();
/* 167:167 */         i = Integer.parseInt(str.substring(str.lastIndexOf(':') + 1, str.lastIndexOf(')')));
/* 168:    */       }
/* 169:    */       catch (Exception localException2) {}
/* 170:170 */       int j = 0;
/* 171:171 */       if (i != -1)
/* 172:    */       {
/* 173:172 */         PsiFile localPsiFile2 = FileContextUtil.getContextFile(localPsiFile1);
/* 174:173 */         if (localPsiFile2 != null)
/* 175:    */         {
/* 176:174 */           PsiElement localPsiElement = localPsiFile2.findElementAt(i);
/* 177:175 */           if (localPsiElement != null) {
/* 178:176 */             for (RegExpModifierProvider localRegExpModifierProvider : (RegExpModifierProvider[])RegExpModifierProvider.EP.getExtensions())
/* 179:    */             {
/* 180:177 */               int n = localRegExpModifierProvider.getFlags(localPsiElement, localPsiFile1);
/* 181:178 */               if (n > 0)
/* 182:    */               {
/* 183:179 */                 j = n;
/* 184:180 */                 break;
/* 185:    */               }
/* 186:    */             }
/* 187:    */           }
/* 188:    */         }
/* 189:    */       }
/* 190:186 */       bool = Pattern.compile(this.d.getText(), j).matcher(this.c.getText()).matches();
/* 191:    */     }
/* 192:    */     catch (Exception localException1) {}
/* 193:189 */     this.c.setBackground(bool ? new JBColor(new Color(231, 250, 219), new Color(68, 85, 66)) : new JBColor(new Color(255, 177, 160), new Color(110, 43, 40)));
/* 194:190 */     BalloonImpl localBalloonImpl = (BalloonImpl)this.f.get();
/* 195:191 */     if ((localBalloonImpl != null) && (localBalloonImpl.isDisposed())) {
/* 196:192 */       localBalloonImpl.revalidate();
/* 197:    */     }
/* 198:    */   }
/* 199:    */ }



/* Location:           E:\idea\

 * Qualified Name:     org.intellij.lang.regexp.intention.CheckRegExpForm

 * JD-Core Version:    0.7.0.1

 */